package com.ticket.sass.admin.dto.output.coupons;

import com.ticket.sass.admin.dto.output.WeekTimeOutput;
import com.ticket.sass.admin.model.LabModel;
import com.ticket.sass.common.entity.tenant.CouponEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * @author ywb
 * @date 2024-03-15 14:36
 */
@Data
@ApiModel
public class CouponOutput {
    @ApiModelProperty(value = "优惠券ID")
    private Long id;
    
    @ApiModelProperty(value = "券名称")
    private String name;
    
    @ApiModelProperty(value = "券类型：1 抵扣券，2 满减券，3 折扣券")
    private Short type;
    
    @ApiModelProperty(value = "使用场景：1 影票，2 卖品")
    private Short scene;
    
    @ApiModelProperty(value = "优惠值：抵扣券 - 忽略，满减券 - 表示金额，折扣券 - 表示折扣")
    private BigDecimal value;
    
    @ApiModelProperty(value = "门槛值：抵扣券 - 忽略，满减券 - 表示满多少可用，折扣券 - 表示满多少可用")
    private BigDecimal thresholdValue;
    
    @ApiModelProperty(value = "生效类型：1 指定日期范围，2 领取后指定")
    private Short activateType;
    
    @ApiModelProperty(value = "可用开始日期（take_effect_type=1 时使用）")
    private LocalDate startDate;
    
    @ApiModelProperty(value = "可用结束日期（take_effect_type=1 时使用）")
    private LocalDate endDate;
    
    @ApiModelProperty(value = "领取后 N 天开始生效，0 表示立即生效（take_effect_type=2 时使用）")
    private Integer activateStart;
    
    @ApiModelProperty(value = "生效后 N 天内有效，-1 表示可用日期内有效（take_effect_type=2 时使用）")
    private Integer activateEnd;
    
    @ApiModelProperty(value = "可用时段：0 不限制，1 指定范围")
    private Short availablePeriod;
    
    @ApiModelProperty(value = "周期格式：0,1,2,3,4,5,6（周日~周六）")
    private List<WeekTimeOutput> weekTimes;
    
    @ApiModelProperty(value = "使用说明")
    private String desc;
    
    @ApiModelProperty(value = "领取统计")
    private Integer receiveCount = 0;
    
    @ApiModelProperty(value = "卖品")
    private List<LabModel> commodities;
    
    @ApiModelProperty(value = "卖品")
    private List<LabModel> halls;
    
    @ApiModelProperty(value = "影片")
    private List<LabModel> films;

//    @ApiModelProperty(value = "是否允许会员卡支付时使用")
//    private Boolean allowCard;
    
    @ApiModelProperty(value = "仅限新用户")
    private Boolean newUserOnly;
    
    @ApiModelProperty(value = "会员卡禁用")
    private Boolean memberCardDisabled;
    
    public CouponOutput() {
    }
    
    public static CouponOutput toOutput(CouponEntity coupon) {
        CouponOutput output = new CouponOutput();
        if (Objects.nonNull(coupon)) {
            output.setId(coupon.getId());
            output.setName(coupon.getName());
            output.setType(coupon.getType().getValue());
            output.setScene(coupon.getScene().getValue());
            output.setValue(coupon.getValue());
            output.setThresholdValue(coupon.getThresholdValue());
            output.setActivateType(coupon.getActivateType().getValue());
            output.setStartDate(coupon.getStartDate());
            output.setEndDate(coupon.getEndDate());
            output.setActivateStart(coupon.getActivateStart());
            output.setActivateEnd(coupon.getActivateEnd());
            output.setAvailablePeriod(coupon.getAvailablePeriod().getValue());
            output.setDesc(coupon.getDesc());
            output.setReceiveCount(coupon.getReceiveCount());
            output.setNewUserOnly(coupon.getNewUserOnly());
            output.setMemberCardDisabled(!coupon.getAllowCard());
        }
        return output;
    }
}
